home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Graphics / SPD / Sources / libinf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-27  |  3.8 KB  |  161 lines  |  [TEXT/R*ch]

  1. /*
  2.  * libinf.c - general info routines.
  3.  *
  4.  * Author:  Eric Haines, 3D/Eye, Inc.
  5.  *
  6.  */
  7.  
  8. /*-----------------------------------------------------------------*/
  9. /* include section */
  10. /*-----------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <math.h>
  15. #include <string.h>
  16.  
  17. #include "lib.h"
  18. #include "drv.h"
  19.  
  20.  
  21. /*-----------------------------------------------------------------*/
  22. /* defines/constants section */
  23. /*-----------------------------------------------------------------*/
  24.  
  25. #ifdef OUTPUT_TO_FILE
  26. FILE * gStdout_file = NULL;
  27. #endif /* OUTPUT_TO_FILE */
  28.  
  29.  
  30. /*-----------------------------------------------------------------*/
  31. /* Here are some local variables that are used to control things like
  32.    the current output file, current texture, ... */
  33. FILE *gOutfile      = stdout;
  34. char *gTexture_name = NULL;
  35. int  gTexture_count = 0;
  36. double gTexture_ior = 1.0;
  37. int  gRT_out_format        = OUTPUT_NFF;
  38. int  gRT_orig_format   = OUTPUT_NFF;
  39. int  gU_resolution  = OUTPUT_RESOLUTION;
  40. int  gV_resolution  = OUTPUT_RESOLUTION;
  41. COORD3 gBkgnd_color = {0.0, 0.0, 0.0};
  42. COORD3 gFgnd_color = {0.0, 0.0, 0.0};
  43. double gView_bounds[2][3];
  44. int gView_init_flag = 0;
  45. char *gLib_version_str = LIB_VERSION;
  46.  
  47. surface_ptr gLib_surfaces = NULL;
  48. object_ptr gLib_objects = NULL;
  49. light_ptr gLib_lights = NULL;
  50. viewpoint gViewpoint = {
  51.     {0, 0, -10},
  52.     {0, 0, 0},
  53.     {0, 1, 0},
  54.     45, 1, 1.0e-3, 10, 128, 128,
  55.     { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }
  56. };
  57.  
  58. /* Globals for tracking indentation level of output file */
  59. int    gTab_width = 4;
  60. int    gTab_level = 0;
  61.  
  62.  
  63.  
  64. /*-----------------------------------------------------------------*/
  65. void tab_indent PARAMS((void))
  66. {
  67.     int    k;
  68.     /* Q&D way to do it... */
  69.     for (k=0; k<gTab_width*gTab_level; k++)
  70.     putc(' ', gOutfile);
  71. } /* tab_printf */
  72.  
  73.  
  74. /*-----------------------------------------------------------------*/
  75. void tab_inc PARAMS((void))
  76. {
  77.     gTab_level++;
  78. } /* tab_inc */
  79.  
  80.  
  81. /*-----------------------------------------------------------------*/
  82. void tab_dec PARAMS((void))
  83. {
  84.     gTab_level--;
  85.     if (gTab_level < 0)
  86.     gTab_level = 0;
  87. } /* tab_dec */
  88.  
  89.  
  90. /* Library info functions */
  91.  
  92. /*-----------------------------------------------------------------*/
  93. char *
  94. lib_get_version_str PARAMS((void))
  95. {
  96.     return gLib_version_str;
  97. } /* lib_get_version_str */
  98.  
  99.  
  100. /*-----------------------------------------------------------------*/
  101. /*
  102.  * Routines to set/reset the various output parameters
  103.  */
  104. /*-----------------------------------------------------------------*/
  105. void
  106. lib_set_output_file(new_outfile)
  107.     FILE *new_outfile;
  108. {
  109.     if (new_outfile == NULL)
  110.     gOutfile = stdout;
  111.     else
  112.     gOutfile = new_outfile;
  113. }
  114.  
  115. /*-----------------------------------------------------------------*/
  116. void
  117. lib_set_default_texture(default_texture)
  118.     char *default_texture;
  119. {
  120.     gTexture_name = default_texture;
  121. }
  122.  
  123. /*-----------------------------------------------------------------*/
  124. void
  125. lib_set_raytracer(default_tracer)
  126.     int default_tracer;
  127. {
  128.     if (default_tracer < OUTPUT_VIDEO ||
  129.     default_tracer > OUTPUT_DELAYED) {
  130.     fprintf(stderr, "Unknown renderer index: %d\n", default_tracer);
  131.     exit(1);
  132.     }
  133.     gRT_out_format = default_tracer;
  134. }
  135.  
  136. /*-----------------------------------------------------------------*/
  137. void
  138. lib_set_polygonalization(u_steps, v_steps)
  139.     int u_steps, v_steps;
  140. {
  141.     if ((u_steps > 0) && (v_steps > 0)) {
  142.     gU_resolution = u_steps;
  143.     gV_resolution = v_steps;
  144.     }
  145. }
  146.  
  147. /*-----------------------------------------------------------------*/
  148. void
  149. lookup_surface_stats(index, tcount, tior)
  150.     int index, *tcount;
  151.     double *tior;
  152. {
  153.     surface_ptr temp_ptr = gLib_surfaces;
  154.  
  155.     while (temp_ptr != NULL && temp_ptr->surf_index != index)
  156.     temp_ptr = temp_ptr->next;
  157.     *tior = temp_ptr->ior;
  158.     if (*tior < 1.0) *tior = 1.0;
  159.     *tcount = temp_ptr->surf_index;
  160. }
  161.